import pandas as pd

ChnSentiCorp_htl_ba_2444=pd.read_csv('data/event_detection_17815.csv')

from sklearn.model_selection import StratifiedShuffleSplit

split_first = StratifiedShuffleSplit(n_splits=1, test_size=0.1, random_state=1)
split_second = StratifiedShuffleSplit(n_splits=1, test_size=1 / 9, random_state=1)

for train_index, test_index in split_first.split(ChnSentiCorp_htl_ba_2444, ChnSentiCorp_htl_ba_2444['label']):
    train_data = ChnSentiCorp_htl_ba_2444.iloc[train_index]
    test_data = ChnSentiCorp_htl_ba_2444.iloc[test_index]

# 小tips，第二次分割的时候，所有的操作要完全忘记前面的东西，完全基于新的变量去弄
# 索引的时候是train_data.iloc[train_index]，新的train_data是train_data_
for train_index, validate_index in split_second.split(train_data, train_data['label']):
    train_data_ = train_data.iloc[train_index]
    validate_data = train_data.iloc[validate_index]

# # 检验是否发生数据交叉
# train_index_set = set(train_data_.index)
# validate_index_set = set(validate_data.index)
# test_index_set = set(test_data.index)
#
# if train_index_set.intersection(validate_index_set) or train_index_set.intersection(
#         test_index_set) or validate_index_set.intersection(test_index_set):
#     print("发生数据交叉")
# else:
#     print("数据被隔离划分")


train_text, train_label = list(train_data_['review']), list(train_data_['label'])

val_text, val_label = list(validate_data['review']), list(validate_data['label'])

test_text, test_label = list(test_data['review']), list(test_data['label'])
